class Walker {
    k
    dx
    dy
    height
    width

    constructor(peeker) {
        this.sign = 1;
        this.peeker = peeker
    }

    reset(direction) {
        let yDirection = ['ArrowLeft', 'ArrowRight'].includes(direction);
        [this.k, this.dx, this.dy] = yDirection ? [1, 0, 1] : [0, 1, 0]
    }

    go(pos) {
        if (this.k)
            this.peeker.trans()

        let cutPoints = this.getCutPoints()
        let enteringPoints = cutPoints.map(([x, y]) => [x + this.dx, y + this.dy])
        this.push(enteringPoints)
        let leavingPoints = this.pop()

        this.peeker.removeState(leavingPoints, 'peek')
        this.peeker.addState(enteringPoints, 'peek')

        // this.peeker.toggleState(leavingPoints, 'peek')
        // this.peeker.toggleState(enteringPoints, 'peek')

        this.peeker.removeState(pos, 'cloaked', 'peek', 'player')
        pos[this.k] += this.sign
        this.peeker.addState(pos, 'player')

        if (this.k)
            this.peeker.trans()
    }

    getCutPoints() {
    }

    push(_) {
    }

    pop() {
    }
}

export class NegWalker extends Walker {
    reset(direction) {
        super.reset(direction);
        [this.sign, this.dx, this.dy] = [-1, -this.dx, -this.dy]
    }

    getCutPoints() {
        return this.peeker.array[0]
    }

    push(entries) {
        this.peeker.array.unshift(entries)
    }

    pop() {
        return this.peeker.array.pop()
    }
}

export class PosWalker extends Walker {
    getCutPoints() {
        return this.peeker.array.slice(-1)[0]
    }

    push(entries) {
        this.peeker.array.push(entries)
    }

    pop() {
        return this.peeker.array.shift()
    }
}
